package com.kelvin.paopao.module.market.wallet.detail;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kelvin.paopao.R;
import com.kelvin.paopao.adapter.WalletDetailAdapter;
import com.kelvin.paopao.api.responseBean.WalletDetailModel;
import com.kelvin.paopao.injector.components.DaggerWalletDetailComponent;
import com.kelvin.paopao.injector.modules.WalletDetailModule;
import com.kelvin.paopao.module.base.BaseActivity;
import com.kelvin.paopao.widgets.CustomToolbar;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by MCK on 2017/5/23.
 */

public class WalletDetailActivity extends BaseActivity<WalletDetailPresenter>
        implements IWalletDetailView {
    @BindView(R.id.custom_toolbar)
    CustomToolbar customToolbar;

    @Inject
    WalletDetailAdapter adapter;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;

    private LinearLayoutManager manager;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_wallet_detail;
    }

    @Override
    protected void initInjector() {
        DaggerWalletDetailComponent.builder().walletDetailModule(new WalletDetailModule(this))
                .build().inject(this);
    }

    @Override
    protected void initViews() {
        customToolbar.showBackIcon(this);
        manager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);
    }

    @Override
    protected void updateViews(boolean isRefresh) {
        mPresenter.getData(isRefresh);
    }

    public static void launch(Context context) {
        Intent intent = new Intent(context, WalletDetailActivity.class);
        context.startActivity(intent);
    }

    @Override
    public void loadData(List<WalletDetailModel> models) {
        if(models!=null&&models.size()!=0){
            adapter.setNewData(models);
        }else{
            View headerView= LayoutInflater.from(this).inflate
                    (R.layout.view_no_data, (ViewGroup) recyclerView.getParent(),false);
            adapter.setEmptyView(headerView);
        }

    }
}
